package org.example.petitionplatformsystem.service.Impl;

import org.example.petitionplatformsystem.dao.NewsRepository;
import org.example.petitionplatformsystem.dao.model.News;
import org.example.petitionplatformsystem.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsRepository newsRepository;

    @Override
    public void addNews(News news) {
        newsRepository.save(news);
    }

    @Override
    public void deleteNews(long id) {
           newsRepository.deleteById(id);
    }

    @Override
    public void updateNews(News news) {
       newsRepository.save(news);
    }

    @Override
    public List<News> getAllNews() {
        return newsRepository.findAll();
    }

    @Override
    public List<News> getCategoriesByCategoryID(long id) {
        return newsRepository.getCategoriesByCategoryID(id);
    }

    @Override
    public News getNewsById(long id) {
        return newsRepository.getReferenceById(id);
    }
}
